package restserver

import (
	"github.com/gin-gonic/gin"
	socketio "github.com/googollee/go-socket.io"
)

type ServerOption func(*Server)

func WithEnableProfiling(enable bool) ServerOption {
	return func(s *Server) {
		s.enableProfiling = enable
	}
}

func WithDefaultHealthCheck(enable bool) ServerOption {
	return func(s *Server) {
		s.enableDefaultHealth = enable
	}
}

func WithDebugMode() ServerOption {
	return func(s *Server) {
		s.mode = gin.DebugMode
	}
}
func WithReleaseMode() ServerOption {
	return func(s *Server) {
		s.mode = gin.ReleaseMode
	}
}
func WithTestMode() ServerOption {
	return func(s *Server) {
		s.mode = gin.TestMode
	}
}

func WithAddress(addr string) ServerOption {
	return func(s *Server) {
		s.address = addr
	}
}

func WithMiddlewares(middlewares ...gin.HandlerFunc) ServerOption {
	return func(s *Server) {
		s.middlewares = middlewares
	}
}

// WithTLSConfig with TLS config.
func WithTLSConfig(certFile, keyFile string) ServerOption {
	return func(o *Server) {
		o.enableTls = true
		o.certFile = certFile
		o.keyFile = keyFile
	}
}

func WithZhTransNames() ServerOption {
	return func(s *Server) {
		s.transName = "zh"
	}
}

func WithEnTransNames() ServerOption {
	return func(s *Server) {
		s.transName = "en"
	}
}
func WithSocketIoServer(socketIoServer *socketio.Server) ServerOption {
	return func(s *Server) {
		s.socketIoServer = socketIoServer
	}
}

func WithEnableSocketIoServer(enableSocketIoServer bool) ServerOption {
	return func(s *Server) {
		s.enableSocketIoServer = enableSocketIoServer
	}
}

// WithClientEnableTracing 设置是否开启链路追踪
func WithClientEnableTracing(enableTracing bool) ServerOption {
	return func(s *Server) {
		s.enableTracing = enableTracing
	}
}

func WithTransName(transName string) ServerOption {
	return func(s *Server) {
		s.transName = transName
	}
}

func WithEnableMetrics(enable bool) ServerOption {
	return func(s *Server) {
		s.enableMetrics = enable
	}
}
